package interfaceGrafica;

import java.awt.datatransfer.Transferable;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DragGestureEvent;
import java.awt.dnd.DragGestureListener;
import java.awt.dnd.DragSource;
import java.awt.dnd.DragSourceDragEvent;
import java.awt.dnd.DragSourceDropEvent;
import java.awt.dnd.DragSourceEvent;
import java.awt.dnd.DragSourceListener;

import javax.swing.ImageIcon;
import javax.swing.JLabel;

import dominioProblema.Pedra;

public class Peca extends JLabel implements DragGestureListener, DragSourceListener {
	protected static final long serialVersionUID = 1L;
	protected DragSource dragSource;
	protected ImageIcon icone;
	protected Pedra pedra;

    public Peca(Pedra pedra) {
    	this.pedra = pedra;
    	String valorPeca = pedra.getPeca();
    	setText(" ");
    	icone = new ImageIcon(getClass().getResource("/imagens/" + valorPeca + ".png"));
    	setIcon(icone);
    	dragSource = new DragSource();
    	dragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_MOVE, this);
    }

    public void dragGestureRecognized(DragGestureEvent evt) {
    	Transferable transferable = new TransferidorPedra(pedra);
    	dragSource.startDrag(evt, DragSource.DefaultCopyDrop, transferable, this);
    }

    public void dragEnter(DragSourceDragEvent evt) {
    }

    public void dragOver(DragSourceDragEvent evt) {
    }

    public void dragExit(DragSourceEvent evt) {
    }

    public void dropActionChanged(DragSourceDragEvent evt) {
    }

    public void dragDropEnd(DragSourceDropEvent evt) {
    	setVisible(false);
    }

}
